package com.mon4cc.simulation;

import com.mon4cc.simulation.utils.BpmnUtils;
import org.jbpt.pm.FlowNode;
import org.jbpt.pm.bpmn.BpmnControlFlow;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;

import java.util.Map;
import java.util.Set;

/**
 * @author Ping
 * @date 2022/12/19 11:34
 **/
public class AndGatewaySimulatedInstance extends FlowNodeSimulatedInstance  {
    private Set<BpmnControlFlow<FlowNode>> inputControlFlows ;
    private int tokenNum ;
    public AndGatewaySimulatedInstance(TokenBasedBPMNSimulation bpmnSimulation, FlowNode flowNode) {
        super(bpmnSimulation, flowNode);
        inputControlFlows = bpmnSimulation.getInputControlflow(flowNode) ;
        this.tokenNum = 0 ;


    }
    @Override
    public void emptyToken() {
        this.enabled = false ;
        this.tokenNum = 0 ;
    }
    @Override
    public void getTokenFrom(FlowNodeSimulatedInstance fromNode) {
        this.tokenNum ++ ;
        fromNode.emptyToken();
        // when all sources of input control flows are executed, then this And-gateway instance was enabled.
        if (this.tokenNum == inputControlFlows.size()) {
            this.enabled = true;
        }
    }

}
